﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using BEGDC.Utility.Castle;
using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.CC.BL.UserManagement;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.CCFlow.CV;
using BEGDC.CC.BL.CCFlow.EV;
using BEGDC.CC.BL.CCFlow.CR;
using BEGDC.CC.BL.CCFlow.OCV;
using BEGDC.CC.BL.CCFlow.OCR;
using BEGDC.CC.BL.CCFlow.EBDCV;
using BEGDC.CC.BL.CCFlow.EBD;
using BEGDC.CC.BL.CCFlow.ESCCV;
using BEGDC.CC.BL.CCFlow.ESC;
using BEGDC.CC.Web.UserControls;
using BEGDC.CC.BL.Email;

namespace BEGDC.CC.Web.Workflow
{
    /// <summary>
    /// Summary description for WorkflowExecution.
    /// </summary>
    public class WorkflowView : System.Web.UI.Page, BEGDC.CC.Web.UserControls.IPageAccess
    {
        protected System.Web.UI.WebControls.Label lbTitle;
        protected System.Web.UI.WebControls.PlaceHolder MainBody;
        protected System.Web.UI.WebControls.TextBox tbCommentView;
        protected System.Web.UI.HtmlControls.HtmlTableCell tabWorkflow;
        protected System.Web.UI.HtmlControls.HtmlTableCell tabApplication;
        protected System.Web.UI.HtmlControls.HtmlTableCell tabFeedback;
        protected System.Web.UI.HtmlControls.HtmlTableCell tabMeetingMinutes;
        protected System.Web.UI.HtmlControls.HtmlTableCell tabAttachment;
        protected System.Web.UI.HtmlControls.HtmlTableCell td_MeetingMinutes;
        protected System.Web.UI.HtmlControls.HtmlTableCell td_Feedback;
        protected System.Web.UI.HtmlControls.HtmlTableRow tr_Title;
        protected System.Web.UI.WebControls.TextBox tbIsMeetingMinutes;
        protected System.Web.UI.WebControls.TextBox tbIsSurvey;
        protected System.Web.UI.WebControls.TextBox tbOperationContent;
        //Button
        protected System.Web.UI.WebControls.Button btnCallback;
        protected System.Web.UI.WebControls.Button btnCancel;
        protected System.Web.UI.WebControls.Button btnCopy;
        protected System.Web.UI.WebControls.Button btnReAssign;
        protected System.Web.UI.WebControls.Button btnDrawback;
        protected System.Web.UI.WebControls.Button btnPending;
        protected System.Web.UI.WebControls.Button btnResume;
        protected System.Web.UI.WebControls.Button btnModify;

        private const string APPLICATION = "App";
        private const string ATTACHMENT = "Att";
        private const string FEEDBACK = "Fee";
        private const string MEETINGMINUTES = "Mee";
        private const string WORKFLOW = "Wor";

        //private bool IsTransaction = false;

        protected BEGDC.CC.Web.UserControls.CR.PrintCtrl PrintCtrl;
        protected BEGDC.CC.Web.UserControls.CV.CVPrintCtrl cvPrintCtrl;
        protected BEGDC.CC.Web.UserControls.CV.CVFeedbackPrintCtrl cvFeedbackPrintCtrl;

        private bool IsModify
        {
            set { ViewState["IsModify"] = value; }
            get
            {
                if (ViewState["IsModify"] == null)
                    return false;
                return (bool)ViewState["IsModify"];
            }
        }
        private bool IsMee
        {
            get
            {
                string state = this.Request.QueryString["IsMee"];
                if (state == null) return false;
                return state == "Y";
            }
        }
        private bool IsSur
        {
            get
            {
                string state = this.Request.QueryString["IsSur"];
                if (state == null) return false;
                return state == "Y";
            }
        }
        protected string Step
        {
            get
            {
                IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
                FlowInstance flowInstance = queryService.QueryFlowInstance(this.ApplicationID);
                if (flowInstance == null)
                    return WorkTransition.Draft;
                else
                    return flowInstance.CurrentActiveStep.StepCode;
            }
        }

        protected new virtual BEGDC.CC.Entity.LogisticalInfo Logist
        {
            get
            {
                IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                return queryService.GetLogisticalInfo(this.ApplicationID);
            }
        }

        private AccessControl _access;
        public AccessControl Access
        {
            set { _access = value; }
            get { return _access; }
        }

        private void Page_Load(object sender, System.EventArgs e)
        {
            this.Access = AccessControlFactory.GetAccessControl(Request.QueryString["PDType"]);
            this.Access.AppId = this.ApplicationID;
            this.Access.State = Request.QueryString["State"];
            this.Access.Tab = Request.QueryString["Type"];

            if (!Page.IsPostBack)
            {
                this.btnResume.Attributes.Add("onclick", "javascript:OpenCommentPaneView();");
                this.btnDrawback.Attributes.Add("onclick", "javascript:OpenCommentPaneView();");
                this.btnPending.Attributes.Add("onclick", "javascript:OpenCommentPaneView();");
                this.btnCancel.Attributes.Add("onclick", "javascript:OpenCommentPaneView();");
                this.btnCallback.Attributes.Add("onclick", "javascript:if(confirm('Are you sure to drawback the application?')){OpenCommentPaneView();}else{event.returnValue = false;}");
                this.btnReAssign.Attributes.Add("onclick", "javascript:OpenAssignPane(" + Request.QueryString["AppID"] + ");");
            }
            this.LoadStateUI();
            if (!Page.IsPostBack)
            {
                SetTabStyle();
                LoadStates();
            }

            if (OpenCVFeedbackForFillInAdvance())
            {
                this.tr_Title.Visible = false;
            }
        }

        private bool OpenCVFeedbackForFillInAdvance()
        {
            string type = string.Empty;
            if (Request.QueryString["Type"] != null)
                type = Request.QueryString["Type"].ToString();
            if (type == APPLICATION)
            {
                return false;
            }
            if (this.ProcessDefinitionType != WorkflowTypes.CV)
                return false;

            if ((this.Step != WorkTransition.CV_PSOApprove && this.Step != WorkTransition.CV_CODVPApprove
                && this.Step != WorkTransition.CV_CODDirectorApprove && this.Step != WorkTransition.CV_CATDIRECTORApprove
                && this.Step != WorkTransition.CV_Check && this.Step != WorkTransition.CV_Assignment))
                return false;


            IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
            BEGDC.CC.Entity.Application app = queryService.GetAppById(this.ApplicationID);


            if ((HttpContext.Current.User.Identity.Name == app.RequesterNameEN)
                && (this.Step == "PSOApprove" || this.Step == "CODVPApprove"
                || this.Step == "CODDirectorApprove" || this.Step == "CATDirectorApprove")
                || this.Step == "CheckApp" || this.Step == WorkTransition.CV_Assignment)
                return true;
            return false;
        }

        private void LoadStates()
        {
            IDefinition def = BEGDC.Utility.Castle.AppContainer.Instance[ServiceConst.DefinitionService] as IDefinition;
            def.GetDefinition();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.btnResume.Click += new EventHandler(btnResume_Click);
            this.btnDrawback.Click += new EventHandler(btnDrawback_Click);
            this.btnPending.Click += new EventHandler(btnPending_Click);
            this.btnCallback.Click += new EventHandler(btnCallback_Click);
            this.btnCancel.Click += new EventHandler(btnCancel_Click);
            this.btnReAssign.Click += new EventHandler(btnReAssign_Click);
            this.btnModify.Click += new EventHandler(btnModify_Click);
            this.btnCopy.Click += new EventHandler(btnCopy_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion

        private string ProcessDefinitionType
        {
            get
            {
                string pdType = this.Request.QueryString["PDType"];
                if (pdType == null) return string.Empty;
                return pdType;
            }
        }

        private int ApplicationID
        {
            get
            {
                string appID = this.Request.QueryString["AppID"];
                if (appID == null) return 0;
                return Convert.ToInt32(appID);
            }
        }

        private void LoadStateUI()
        {
            UserControl obj = null;
            string type = APPLICATION;
            btnResume.Visible = false;

            if (Request.QueryString["Type"] != null)
                type = Request.QueryString["Type"].ToString();

            try
            {
                #region move to access control
                //				IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
                //				if(this.Step == BEGDC.CC.BL.Workflow.WorkTransition.End)
                //				{
                //					this.btnPending.Visible = false;
                //					this.btnDrawback.Visible = false;
                //					this.btnResume.Visible = false;
                //					this.btnCallback.Visible = false;
                //					this.btnCancel.Visible = false;
                //					this.btnReAssign.Visible = false;
                //				}
                //				else if(Request.QueryString["State"] == SysDicItem.ProjectStatusFlag.Pending)
                //				{
                //					this.btnPending.Visible = false;
                //					this.btnDrawback.Visible = false;
                //					this.btnCallback.Visible = false;
                //					this.btnCancel.Visible = false;
                //					
                //					if(userService.IsCODManager(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.Id, Request.QueryString["PDType"]))
                //					{
                //						this.btnReAssign.Visible = true;
                //						this.btnResume.Visible = true;
                //					}
                //					else
                //					{
                //						this.btnReAssign.Visible = false;
                //						if(userService.IsCODStaff(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.Id, Request.QueryString["PDType"]))
                //							this.btnResume.Visible = true;
                //						else
                //							this.btnResume.Visible = false;
                //					}
                //				}
                //				else if(Request.QueryString["State"] == SysDicItem.ProjectStatusFlag.End)
                //				{
                //					this.btnPending.Visible = false;
                //					this.btnDrawback.Visible = false;
                //					this.btnResume.Visible = false;
                //					this.btnCallback.Visible = false;
                //					this.btnCancel.Visible = false;
                //					this.btnReAssign.Visible = false;
                //				}
                //				else if(Request.QueryString["State"] == SysDicItem.ProjectStatusFlag.CANCEL)
                //				{
                //					this.btnPending.Visible = false;
                //					this.btnDrawback.Visible = false;
                //					this.btnResume.Visible = false;
                //					this.btnCallback.Visible = false;
                //					this.btnCancel.Visible = false;
                //					this.btnReAssign.Visible = false;
                //					this.btnCopy.Visible = true;
                //				}
                //				else
                //				{
                //					if(userService.IsCODStaff(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.Id, Request.QueryString["PDType"]) ||
                //						userService.IsCODManager(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.Id, Request.QueryString["PDType"]))
                //					{
                //						this.btnPending.Visible = true;
                //						this.btnCancel.Visible = true;
                //					}
                //					else
                //					{
                //						this.btnPending.Visible = false;
                //						this.btnCancel.Visible = false;
                //					}
                //
                //					if(userService.IsLastOperator(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.NameEN, this.ApplicationID))
                //						this.btnDrawback.Visible = true;
                //					else
                //						this.btnDrawback.Visible = false;
                //
                //					if(userService.IsApplicant(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.Id, this.ApplicationID))
                //						this.btnCallback.Visible = true;
                //					else
                //						this.btnCallback.Visible = false;
                //
                //					if(userService.IsCODManager(((CCIdentity)HttpContext.Current.User.Identity).UserInfo.Id, Request.QueryString["PDType"]))
                //						this.btnReAssign.Visible = true;
                //					else
                //						this.btnReAssign.Visible = false;
                //				}
                #endregion
                this.Access.CheckExcutionViewButton();
                this.btnCallback.Visible = this.Access.IsShowCallbackButton;
                this.btnCancel.Visible = this.Access.IsShowCancelButton;
                this.btnDrawback.Visible = this.Access.IsShowDrawbackButton;
                this.btnPending.Visible = this.Access.IsShowSuspendButton;
                this.btnReAssign.Visible = this.Access.IsShowReAssignButton;
                this.btnResume.Visible = this.Access.IsShowResumeButton;
                this.btnCopy.Visible = this.Access.IsShowViewCopyButton;
                this.btnModify.Visible = this.Access.IsShowModifyButton;
                this.PrintCtrl.Visible = false;
                this.cvPrintCtrl.Visible = false;

                if (type == APPLICATION)
                {

                    if (this.ProcessDefinitionType == WorkflowTypes.EV)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.EV.EVApplication);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/EV/EVApplication.ascx");
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.CV)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.CV.CATApprove);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/CV/CATApprove.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.CR)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.CR.CATVPApproval);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/CR/CATVPApproval.ascx");
                        this.PrintCtrl.Visible = this.Access.IsShowPrintButton;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.CO)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.OutCR.Request);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/OutCR/Request.ascx");
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.OCV.OCVCtrl);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/OCV/OCVCtrl.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                        this.cvPrintCtrl.ProcessType = WorkflowTypes.OCV;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.OCR.OCRCtrl);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/OCR/Paticipation.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                        this.cvPrintCtrl.ProcessType = WorkflowTypes.OCR;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.EBDCV.EBDCVCtrl);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/EBDCV/EBDCVCtrl.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                        this.cvPrintCtrl.ProcessType = WorkflowTypes.EBDCV;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.EBD.EBDCtrl);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/EBD/Paticipation.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                        this.cvPrintCtrl.ProcessType = WorkflowTypes.EBD;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.ESCCV.ESCCVCtrl);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/ESCCV/ESCCVCtrl.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                        this.cvPrintCtrl.ProcessType = WorkflowTypes.ESCCV;
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
                    {
                        Type delegationType = typeof(BEGDC.CC.Web.UserControls.ESC.ESCCtrl);
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/ESC/Paticipation.ascx");
                        this.cvPrintCtrl.Visible = this.Access.IsShowPrintButton;
                        this.cvPrintCtrl.ProcessType = WorkflowTypes.ESC;
                    }
                }
                else if (type == ATTACHMENT)
                {
                    Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.CommonAttachment");
                    obj = (UserControl)Activator.CreateInstance(delegationType, false);
                    obj = (UserControl)Page.LoadControl("../UserControls/CommonAttachment.ascx");
                }
                else if (type == WORKFLOW)
                {
                    Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.ActionLog");
                    obj = (UserControl)Activator.CreateInstance(delegationType, false);
                    obj = (UserControl)Page.LoadControl("../UserControls/ActionLog.ascx");
                }
                else if (type == MEETINGMINUTES)
                {
                    Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.EV.ApproveMM");
                    obj = (UserControl)Activator.CreateInstance(delegationType, false);
                    obj = (UserControl)Page.LoadControl("../UserControls/EV/ApproveMM.ascx");
                }
                else if (type == FEEDBACK)
                {
                    if (this.ProcessDefinitionType == WorkflowTypes.CV)
                    {
                        Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.CV.Feedback");
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/CV/Feedback.ascx");
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.CR)
                    {
                        Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.CR.CRSurvey");
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/CR/CRSurvey.ascx");
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
                    {
                        Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.OCR.OCRSurvey");
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/OCR/OCRSurvey.ascx");
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
                    {
                        Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.EBD.EBDSurvey");
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/EBD/EBDSurvey.ascx");
                    }
                    else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
                    {
                        Type delegationType = Type.GetType("BEGDC.CC.Web.UserControls.ESC.ESCSurvey");
                        obj = (UserControl)Activator.CreateInstance(delegationType, false);
                        obj = (UserControl)Page.LoadControl("../UserControls/ESC/ESCSurvey.ascx");
                    }
                }

                this.MainBody.Controls.Clear();
                this.MainBody.Controls.Add(obj);
            }
            catch
            {
                // 任何地方出错直接转向到ErrorPage.aspx
                throw;
            }


            // Always display attachment page except CR
            if (Request.QueryString["PDType"] != null && Request.QueryString["PDType"] != WorkflowTypes.CR)
            {
                Type t = Type.GetType("BEGDC.CC.Web.UserControls.CommonAttachment");
                obj = (UserControl)Activator.CreateInstance(t, false);
                obj = (UserControl)Page.LoadControl("../UserControls/CommonAttachment.ascx");
                this.MainBody.Controls.Add(obj);
            }
        }

        void btnDrawback_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.Drawback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                crService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.DrawBack(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');window.close();</script>");
        }

        void btnPending_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                crService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.Suspend(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');window.close();</script>");
        }

        void btnResume_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                crService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.Resume(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }

            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');window.close();</script>");
        }

        public bool IsFeedBack
        {
            get
            {
                return (this.tbIsSurvey.Text == "Y" && !this.IsSur);
            }
        }

        private void SetTabStyle()
        {
            string type = APPLICATION;
            if (Request.QueryString["Type"] != null)
                type = Request.QueryString["Type"].ToString();
            if (this.tbIsMeetingMinutes.Text == "Y" && !this.IsMee)
                type = MEETINGMINUTES;
            if (this.tbIsSurvey.Text == "Y" && !this.IsSur)
                type = FEEDBACK;

            switch (type)
            {
                case APPLICATION:
                    this.tabApplication.Attributes.Add("class", "TAB_1");
                    this.cvFeedbackPrintCtrl.Visible = false;
                    break;
                case ATTACHMENT:
                    this.tabAttachment.Attributes.Add("class", "TAB_1");
                    this.cvFeedbackPrintCtrl.Visible = false;
                    this.btnCopy.Visible = false;
                    break;
                case WORKFLOW:
                    this.tabWorkflow.Attributes.Add("class", "TAB_1");
                    this.cvFeedbackPrintCtrl.Visible = false;
                    this.btnCopy.Visible = false;
                    break;
                case FEEDBACK:
                    this.tabFeedback.Attributes.Add("class", "TAB_1");
                    this.PrintCtrl.Visible = false;
                    this.cvPrintCtrl.Visible = false;
                    if (this.ProcessDefinitionType == WorkflowTypes.CV)
                        this.cvFeedbackPrintCtrl.Visible = Access.IsShowFeedbackPrintButton;
                    else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
                    {
                        this.cvFeedbackPrintCtrl.Visible = false;
                        this.cvPrintCtrl.Visible = true;
                        this.cvPrintCtrl.ProcessType = "OCR_Feedback";
                    }

                    else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
                    {
                        this.cvFeedbackPrintCtrl.Visible = false;
                        this.cvPrintCtrl.Visible = true;
                        this.cvPrintCtrl.ProcessType = "EBD_Feedback";
                    }

                    else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
                    {
                        this.cvFeedbackPrintCtrl.Visible = false;
                        this.cvPrintCtrl.Visible = true;
                        this.cvPrintCtrl.ProcessType = "ESC_Feedback";
                    }

                    this.btnCopy.Visible = false;
                    break;
                case MEETINGMINUTES:
                    this.tabMeetingMinutes.Attributes.Add("class", "TAB_1");
                    this.cvFeedbackPrintCtrl.Visible = false;
                    this.btnCopy.Visible = false;
                    break;
            }

            string pdtype = Request.QueryString["PDType"].ToString();
            switch (pdtype)
            {
                case WorkflowTypes.CV:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    if (this.Step != WorkTransition.CV_Feedback && this.Step != WorkTransition.End
                        && this.Step != WorkTransition.CV_Close && this.Step != WorkTransition.CV_CATDIRECTORApprove
                        && this.Step != WorkTransition.CV_CODDirectorApprove && this.Step != WorkTransition.CV_CODVPApprove && this.Step != WorkTransition.CV_PSOApprove
                        && this.Step != WorkTransition.CV_Check && this.Step != WorkTransition.CV_Assignment)
                    {
                        this.tabFeedback.Visible = false;
                        this.td_Feedback.Visible = false;
                    }
                    break;
                case WorkflowTypes.CR:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    if ((this.Step != WorkTransition.CR_CRSurvey && this.Step != WorkTransition.End && this.Step != WorkTransition.CR_CloseApp)
                        || (this.Logist != null && (this.Logist.TravelAgency == null || this.Logist.TravelAgency == string.Empty)))
                    {
                        this.tabFeedback.Visible = false;
                        this.td_Feedback.Visible = false;
                    }
                    break;
                case WorkflowTypes.CO:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    this.tabFeedback.Visible = false;
                    this.td_Feedback.Visible = false;
                    break;
                case WorkflowTypes.EV:
                    this.tabFeedback.Visible = false;
                    this.td_Feedback.Visible = false;
                    if ((this.Step != WorkTransition.EV_MeetingMinutes && this.Step != WorkTransition.EV_CODStaffCheckMM
                        && this.Step != WorkTransition.EV_PSOApproveMM && this.Step != WorkTransition.EV_Close
                        && this.Step != WorkTransition.EV_CATApproveMM && this.Step != WorkTransition.EV_End))
                    {
                        this.tabMeetingMinutes.Visible = false;
                        this.td_MeetingMinutes.Visible = false;
                    }
                    break;
                case WorkflowTypes.OCV:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    this.tabFeedback.Visible = false;
                    this.td_Feedback.Visible = false;
                    break;
                case WorkflowTypes.OCR:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    if (this.Step != WorkTransition.OCR_OCRSurvey && this.Step != WorkTransition.End
                        && this.Step != WorkTransition.OCR_CloseApp)
                    {
                        this.tabFeedback.Visible = false;
                        this.td_Feedback.Visible = false;
                    }
                    break;
                case WorkflowTypes.EBDCV:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    this.tabFeedback.Visible = false;
                    this.td_Feedback.Visible = false;
                    break;
                case WorkflowTypes.EBD:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    if (this.Step != WorkTransition.EBD_EBDSurvey && this.Step != WorkTransition.End
                        && this.Step != WorkTransition.EBD_CloseApp)
                    {
                        this.tabFeedback.Visible = false;
                        this.td_Feedback.Visible = false;
                    }
                    break;
                case WorkflowTypes.ESCCV:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    this.tabFeedback.Visible = false;
                    this.td_Feedback.Visible = false;
                    break;
                case WorkflowTypes.ESC:
                    this.tabMeetingMinutes.Visible = false;
                    this.td_MeetingMinutes.Visible = false;
                    if (this.Step != WorkTransition.ESC_ESCSurvey && this.Step != WorkTransition.End
                        && this.Step != WorkTransition.ESC_CloseApp)
                    {
                        this.tabFeedback.Visible = false;
                        this.td_Feedback.Visible = false;
                    }
                    break;
            }

        }

        void btnCallback_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                crService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.Callback(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                crService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.Cancel(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbCommentView.Text));
            }
            IEmail email = AppContainer.Instance[ServiceConst.EmailService] as IEmail;
            email.Send(this.ApplicationID, EmailTemplate.CancelMail);
            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');window.close();</script>");
        }

        void btnCopy_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.CopyEV(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.CopyCV(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                //SaveCR();

                ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                CRService.CopyCR(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.CopyOCV(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.CopyCR(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.CopyEBDCV(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.CopyCR(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.CopyESCCV(this.ApplicationID);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.CopyCR(this.ApplicationID);
            }
            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CM004 + "');</script>");
        }

        private DataTable InitializeDataTable(System.Data.DataTable dataTable)
        {
            if (dataTable == null || dataTable.Rows.Count == 0)
                return null;
            DataRow dataRow;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                dataRow = dataTable.Rows[i];
                dataRow[0] = 0;
            }
            return dataTable;
        }


        private void ConvertDatatableToList(DataTable dtSite, DataTable dtCustomer, DataTable dtAL, DataTable dtCost,
            DataTable dtContract, ref IList customerAttendee, ref IList alAttendee, ref IList site, ref IList cost, ref IList contract)
        {
            // site info
            if (dtSite != null && dtSite.Rows.Count > 0)
            {
                for (int i = 0; i < dtSite.Rows.Count; i++)
                {
                    AppVisitingSite appSite = new AppVisitingSite();
                    appSite.Site = new DicItem();
                    appSite.Site.Id = Convert.ToInt32(dtSite.Rows[i]["DicItemID"]);

                    site.Add(appSite);
                }
            }

            // Customer Attendee Info
            if (dtCustomer != null && dtCustomer.Rows.Count > 0)
            {
                for (int i = 0; i < dtCustomer.Rows.Count; i++)
                {
                    CustomerAttendee cus = new CustomerAttendee();
                    cus.NameEN = dtCustomer.Rows[i]["Name"].ToString();
                    cus.Title = dtCustomer.Rows[i]["Title"].ToString();
                    cus.Responsibility = new DicItem();
                    cus.Responsibility.Id = Convert.ToInt32(dtCustomer.Rows[i]["ResponsibilityID"]);
                    cus.Affects = new DicItem();
                    cus.Affects.Id = Convert.ToInt32(dtCustomer.Rows[i]["AffectsID"]);
                    cus.IsAttended = true;
                    cus.Remark = dtCustomer.Rows[i]["Remark"].ToString();

                    customerAttendee.Add(cus);
                }
            }

            // AL Attendee Info
            if (dtAL != null && dtAL.Rows.Count > 0)
            {
                for (int i = 0; i < dtAL.Rows.Count; i++)
                {
                    ALAttendee al = new ALAttendee();
                    al.EmployeeId = new Employee();
                    al.EmployeeId.Id = dtAL.Rows[i]["EmployeeId"].ToString();
                    al.Title = dtAL.Rows[i]["Title"].ToString();

                    alAttendee.Add(al);
                }
            }

            // Cost Center Info
            if (dtCost != null && dtCost.Rows.Count > 0)
            {
                for (int i = 0; i < dtCost.Rows.Count; i++)
                {
                    CostCenterRelatedCost co = new CostCenterRelatedCost();
                    co.CostCenterCode = dtCost.Rows[i]["CostCenterCode"].ToString();
                    co.DecryptedCost = Convert.ToDecimal(dtCost.Rows[i]["Cost"]);
                    co.CostType = CostType.Budget;

                    cost.Add(co);
                }
            }

            // Contract Info
            if (dtContract != null && dtContract.Rows.Count > 0)
            {
                for (int i = 0; i < dtContract.Rows.Count; i++)
                {
                    ContractInfo ci = new ContractInfo();
                    ci.DateOfContract = Convert.ToDateTime(dtContract.Rows[i]["DateOfContract"]);
                    ci.ContractNo = dtContract.Rows[i]["ContractNo"].ToString();
                    ci.ProducstSold = dtContract.Rows[i]["ProducstSold"].ToString();
                    ci.VisitPurposeInContract = dtContract.Rows[i]["VisitPurposeInContract"].ToString();
                    ci.Quotas = Convert.ToInt32(dtContract.Rows[i]["Quotas"]);
                    ci.UnitPrice = Convert.ToDecimal(dtContract.Rows[i]["UnitPrice"]);
                    ci.Budget = Convert.ToDecimal(dtContract.Rows[i]["Budget"]);

                    contract.Add(ci);
                }
            }
        }

        void btnReAssign_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
                cvService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR || this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
                crService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                IOCV ocvService = AppContainer.Instance[ServiceConst.OCVService] as IOCV;
                ocvService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                IOCR ocrService = AppContainer.Instance[ServiceConst.OCRService] as IOCR;
                ocrService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                IEBDCV ebdcvService = AppContainer.Instance[ServiceConst.EBDCVService] as IEBDCV;
                ebdcvService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                IEBD ebdService = AppContainer.Instance[ServiceConst.EBDService] as IEBD;
                ebdService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                IESCCV ecscvService = AppContainer.Instance[ServiceConst.ESCCVService] as IESCCV;
                ecscvService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                IESC ecsService = AppContainer.Instance[ServiceConst.ESCService] as IESC;
                ecsService.ReAssign(Convert.ToInt64(Request.QueryString["FlowID"]), this.tbOperationContent.Text);
            }
            Page.RegisterClientScriptBlock("", "<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');</script><script>window.close();</script>");
        }

        void btnModify_Click(object sender, EventArgs e)
        {
            if (this.ProcessDefinitionType == WorkflowTypes.EV)
            {
                UserControls.EV.EVApplication evApp = (UserControls.EV.EVApplication)this.MainBody.Controls[0];
                if (!this.IsModify)
                    evApp.ShowModifyStatus();
                else
                {
                    evApp.Save();
                    evApp.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CV)
            {
                UserControls.CV.CATApprove cv_catapprove = (UserControls.CV.CATApprove)this.MainBody.Controls[0];
                if (!this.IsModify)
                    cv_catapprove.ShowModifyStatus();
                else
                {
                    cv_catapprove.Save();
                    cv_catapprove.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CR)
            {
                UserControls.CR.CATVPApproval cr_catvp = (UserControls.CR.CATVPApproval)this.MainBody.Controls[0];
                if (!this.IsModify)
                    cr_catvp.ShowModifyStatus();
                else
                {
                    cr_catvp.Modify();
                    cr_catvp.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.CO)
            {
                UserControls.OutCR.Request co_request = (UserControls.OutCR.Request)this.MainBody.Controls[0];
                if (!this.IsModify)
                    co_request.ShowModifyStatus();
                else
                {
                    co_request.Modify();
                    co_request.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCV)
            {
                UserControls.OCV.OCVCtrl ctrl = (UserControls.OCV.OCVCtrl)this.MainBody.Controls[0];
                if (!this.IsModify)
                    ctrl.ShowModifyStatus();
                else
                {
                    ctrl.Save();
                    ctrl.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.OCR)
            {
                UserControls.OCR.Paticipation ParticipationCtrl = (UserControls.OCR.Paticipation)this.MainBody.Controls[0];
                if (!this.IsModify)
                    ParticipationCtrl.ShowModifyStatus();
                else
                {
                    ParticipationCtrl.Modify();
                    ParticipationCtrl.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBDCV)
            {
                UserControls.EBDCV.EBDCVCtrl ctrl = (UserControls.EBDCV.EBDCVCtrl)this.MainBody.Controls[0];
                if (!this.IsModify)
                    ctrl.ShowModifyStatus();
                else
                {
                    ctrl.Save();
                    ctrl.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.EBD)
            {
                UserControls.EBD.Paticipation ParticipationCtrl = (UserControls.EBD.Paticipation)this.MainBody.Controls[0];
                if (!this.IsModify)
                    ParticipationCtrl.ShowModifyStatus();
                else
                {
                    ParticipationCtrl.Modify();
                    ParticipationCtrl.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESCCV)
            {
                UserControls.ESCCV.ESCCVCtrl ctrl = (UserControls.ESCCV.ESCCVCtrl)this.MainBody.Controls[0];
                if (!this.IsModify)
                    ctrl.ShowModifyStatus();
                else
                {
                    ctrl.Save();
                    ctrl.EndModifyStatus();
                }
            }
            else if (this.ProcessDefinitionType == WorkflowTypes.ESC)
            {
                UserControls.ESC.Paticipation ParticipationCtrl = (UserControls.ESC.Paticipation)this.MainBody.Controls[0];
                if (!this.IsModify)
                    ParticipationCtrl.ShowModifyStatus();
                else
                {
                    ParticipationCtrl.Modify();
                    ParticipationCtrl.EndModifyStatus();
                }
            }
            if (!this.IsModify)
                //this.btnModify.ImageUrl = "../images/bbw_save.gif";
                this.btnModify.Text = "Save";
            else
                //this.btnModify.ImageUrl = "../images/bb_modify.gif";
                this.btnModify.Text = "Modify";
            this.IsModify = !this.IsModify;
        }
        #region IWorkflowPage Members

        //		public void SetCurrentStatus(string currentStatus)
        //		{
        //			ProcessStateList states = this.ProcessStatesControl1.ProcessStates;
        //			for(int i=0; i<states.Count; i++)
        //			{
        //				for(int j=0; j<states[i].ChildrenStates.Count; j++)
        //				{
        //					ProcessState state = states[i].ChildrenStates[j];
        //					if (state.Key == currentStatus)
        //					{
        //						this.ProcessStatesControl1.OnGoingIndex = i;
        //						this.ProcessStatesControl1.OnGoingSubIndex = j;
        //						return;
        //					}
        //				}
        //			}
        //		}

        //		public bool IsOngoingStep()
        //		{
        //			if ((this.ProcessStatesControl1.OnGoingIndex == this.ProcessStatesControl1.SelectedIndex) &&
        //				(this.ProcessStatesControl1.OnGoingSubIndex == this.ProcessStatesControl1.SelectedSubIndex))
        //				return true;
        //			return false;
        //		}
        //
        //		public int CompareStatus(string currentStatus)
        //		{
        //			int retvalue = -1;
        //			ProcessStateList states = this.ProcessStatesControl1.ProcessStates;
        //			for(int i=0; i<states.Count; i++)
        //			{
        //				for(int j=0; j<states[i].ChildrenStates.Count; j++)
        //				{
        //					ProcessState state = states[i].ChildrenStates[j];
        //					if ((this.ProcessStatesControl1.OnGoingIndex == i) &&
        //						(this.ProcessStatesControl1.OnGoingSubIndex == j))
        //					{
        //						retvalue = 0;
        //					}
        //					else if (retvalue == 0)
        //					{
        //						retvalue = 1;
        //					}
        //					if (state.Key == currentStatus)
        //					{
        //						return retvalue;
        //					}
        //				}
        //			}
        //			return retvalue;
        //		}
        #endregion
    }
}
